//# sourceURL=http://uMapApp/Module/WorkManageModule/WorkAreaPointModule
define([
    "mhjs/mhjs",
    "uMap/uMap",
    "uEarth/uEarth",
    "../Module"
    , "../../UI/Layer"
], function (
    mhjs,
    uMap,
    uEarth,
    Module
    , Layer
) {

    function WorkAreaPointModule(option) {

        var _this = this;

        Module.call(_this, option);

        _this.title = "工区分区";
        _this.icon = _this.app.icons.home;

        _this.layer = new Layer({
            "app": _this.app
        });

        _this.layer.pointPrimitives = new uMap.PointPrimitiveCollection();
        _this.layer.primitives.add(_this.layer.pointPrimitives.object);

        _this.layer.labelPrimitives = new uMap.LabelCollection();
        _this.layer.primitives.add(_this.layer.labelPrimitives.object);

        _this.layer.billboardPrimitives = new uMap.BillboardCollection();
        _this.layer.primitives.add(_this.layer.billboardPrimitives.object);


    }

    var _class = WorkAreaPointModule;

    mhjs.Inherit(_class, Module);

    Object.defineProperties(_class.prototype, {
        "open": {
            value: function () {
                var _this = this;

                _this.load(function () {
                    _this.layer.open();
                });

                _this.isOpened = true;
                _this.trigger("open");
                _this.trigger("toggle");
            }
        },
        "close": {
            value: function () {
                var _this = this;
                _this.layer.close();
                _this.isOpened = false;
                _this.trigger("close");
                _this.trigger("toggle");
            }
        },
        "load": {
            value: function (callback) {
                var _this = this;

                var request = new mhjs.Request({
                    "title": "工区点位",
                    "method": "get",
                    "url": "data/workarea/workarea_point.geojson"
                });

                if (!_this.isloaded) {
                    request.send({}, function (json) {
                        if (json.features && json.features.length > 0) {
                            _this.isloaded = true;
                            _this.points = json.features;

                            _this.render();
                            callback && callback();
                        }
                    });
                } else {
                    _this.render();
                    callback && callback();
                }

            }
        },
        "render": {
            value: function () {

                var _this = this;

                if (_this.points) {

                    $.each(_this.points, function (i, item) {

                        item.position = new uMap.Position(item.geometry.coordinates);

                        item.billboard = _this.layer.billboardPrimitives.add(new uMap.BillboardOption({
                            position: item.position
                            , image: (item.properties.title.length <= 6 ? "./img/markpop3.png" : "./img/markpop2.png")
                            , verticalOrigin: "BOTTOM"
                            , level: [0, 1e5]
                            , disableDepthTestDistance: Number.POSITIVE_INFINITY
                        }));

                        item.label = _this.layer.labelPrimitives.add(new uMap.LabelOption({
                            position: item.position
                            , text: item.properties.title
                            , font: "bold 14px Microsoft SansCN"
                            , fillColor: ["#fff"]
                            , outlineColor: ["#06c"]
                            , outlineWidth: 5.0
                            , horizontalOrigin: "CENTER"
                            , verticalOrigin: "BOTTOM"
                            , pixelOffset: [0, -13]
                            , level: [0, 1e5]
                            , disableDepthTestDistance: Number.POSITIVE_INFINITY
                        }));

                        // item.point = _this.layer.pointPrimitives.add(new uMap.PointOption({
                        //     position                  : item.position
                        //     , pixelSize               : 5
                        //     , color                   : ["#ff0"]
                        //     , outlineColor            : ["#000"]
                        //     , outlineWidth            : 2
                        //     , level                   : [0, 1e5]
                        //     , disableDepthTestDistance: Number.POSITIVE_INFINITY
                        // }));
                    });

                }


            }
        }
    });

    return _class;

});